package com.spring.boot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: springboot_vue
 * @description: Swagger2配置类
 * @author: ry
 * @create: 2018-08-17 13:42
 **/
@Configuration
@EnableSwagger2//启动加载swagger2
public class Swagger2 {

    //Swagger2配置文件,可以配置Swagger2的一些基本内容,比如扫描的包等
    @Bean
    public Docket createRestApi(){
          return new Docket(DocumentationType.SWAGGER_2)
                  .apiInfo(apiInfo())
                  .select()
                  .apis(RequestHandlerSelectors.basePackage("com.spring.boot.controller"))
                 // .paths(PathSelectors.any())//四种匹配规则
                  .paths(PathSelectors.regex("/api/.*"))
                  .build();
    }

    //构建api文档的详细信息函数,注意这里的注解引用的是那个
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring_vue 接口文档")
                //创建人
                .contact(new Contact("ry","https://gitee.com/renyong9511/springboot_vue","670298332@qq.com"))
                //版本号
                .version("1.0")
                //api描述
                .description("api接口")
                .build();

    }
}
